package com.yinp.proapp.module.study.dialog.activity;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.yinp.proapp.adapter.ComViewHolder;
import com.yinp.proapp.adapter.CommonAdapter;
import com.yinp.proapp.adapter.SingleViewHolder;
import com.yinp.proapp.base.activity.AppBaseActivity;
import com.yinp.proapp.bean.BaseBean;
import com.yinp.proapp.databinding.ActivityDialogBinding;
import com.yinp.proapp.databinding.ItemBaseBinding;
import com.yinp.proapp.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yinp
 * @Date: 2021/8/19
 * @Description:
 */
public class DialogActivity extends AppBaseActivity<ActivityDialogBinding> {

    private List<BaseBean> dataList = new ArrayList<>();
    private CommonAdapter<BaseBean> adapter;

    @Override
    protected void initViews() {
        setStatusBarHeight(StatusBarUtil.getStatusBarHeight(mContext));
        initClick(bd.header.headerBackImg);
        bd.header.headerCenterTitle.setText("dialog平时中的运用");
        initRecycler();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == bd.header.headerBackImg) {
            finish();
        }
    }

    private void initRecycler() {
        dataList.add(new BaseBean("系统dialog的使用", "com.yinp.proapp.module.study.dialog.activity.SystemDialogActivity"));
//        dataList.add(new BaseBean("自己写的弹窗", "com.yinp.proapp.module.study.dialog.activity.MyCreateWindowActivity"));
//        dataList.add(new BaseBean("recyclerView和recyclerView的滑动冲突", "com.yinp.proapp.module.study.recycler.activity.FlexRecyclerActivity"));
//        dataList.add(new BaseBean("recyclerView实现banner的效果", "com.yinp.proapp.module.study.recycler.activity.FlexRecyclerActivity"));
        adapter = new CommonAdapter<BaseBean>(mContext,dataList) {
            @Override
            protected SingleViewHolder setComViewHolder(View view, int viewType, ViewGroup parent) {
                return new SingleViewHolder(ItemBaseBinding.inflate(mInflater, parent, false));
            }

            @Override
            public void onBindItem(SingleViewHolder holder, int position, BaseBean item) {
                ItemBaseBinding binding = (ItemBaseBinding) holder.getBinding();
                binding.tvTitle.setText(item.getTitle());
            }
        };
        adapter.setOnItemClickListener((position, view) -> {
            if (!TextUtils.isEmpty(dataList.get(position).getUrl())) {
                goToActivity(mContext, dataList.get(position).getUrl());
            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        bd.rvList.setLayoutManager(linearLayoutManager);
        bd.rvList.setHasFixedSize(true);
        bd.rvList.setAdapter(adapter);
    }

    static class ViewHolder extends ComViewHolder {
        ItemBaseBinding binding;

        public ViewHolder(ItemBaseBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }
    }
}